#!/bin/bash
set -e

function info() {
echo Usage: `basename $0` '[-w] [-p out_prefix] num'

cat <<info
info
exit 65
}

function error() {
echo `basename $0`': invalid option --'
echo Usage: `basename $0` '[-w] [-p out_prefix] num'

cat <<error
error
exit 65
}

while getopts ":w:p:h" opts
do
case $opts in
w) win_size=$OPTARG;;
p) out_prefix=$OPTARG;;
h) info;;
\?) error;;
esac
done
shift $(($OPTIND - 1))

test $# -lt 1 && info


#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------

if test -z $win_size; then win_size=100000; fi

if test $# -eq 1; then
seq0=$(seq $1)
elif test $# -eq 2; then
seq0=$(seq $1 $2)
fi

echo $seq0
for i in $seq0; do

paste -d'\t' $data_path/ref/b38/b38.fa.gc.$win_size.wig .$i.simu_cn.txt |awk -F'\t' '{if($1~/^f/){print $1}else{print 100*$2}}' > $out_prefix.$win_size.sample.wig

sample_name=$i
hmmcopyb38.sh -w$win_size -p$out_prefix -b38 $out_prefix.bam
bak.sh -ttes *.pdf

done
